package com.song.tools.mvc.controller;

import com.song.tools.core.beans.response.ResultVo;
import com.song.tools.mvc.request.BatchIdRequest;
import com.song.tools.mvc.request.IdRequest;
import com.song.tools.mvc.request.PageRequest;
import com.song.tools.mvc.response.PageResponse;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import javax.validation.Valid;
import java.io.Serializable;
import java.util.List;

/**
 * CRUD 控制器
 *
 * @author song tools
 * @since 2024-06-25
 */
public interface CrudController<QueryRequest, QueryResponse, SaveRequest, SaveResponse, UpdateRequest, UpdateResponse, PrimaryKey extends Serializable, DeleteResponse> {

    /**
     * 分页查询
     *
     * @param request 请求
     * @return 分页响应
     */
    @Operation(summary = "分页查询")
    @PostMapping("/listPages")
    ResultVo<PageResponse<QueryResponse>> listPages(@Valid @RequestBody PageRequest<QueryRequest> request);


    /**
     * 查询信息（不分页）
     *
     * @param request 请求
     * @return PageResponse 响应
     */
    @Operation(summary = "查询信息（不分页）")
    @PostMapping("/list")
    ResultVo<List<QueryResponse>> list(@Valid @RequestBody QueryRequest request);


    /**
     * 查询详细信息
     *
     * @param request 请求
     * @return 响应
     */
    @PostMapping(value = "/getDetail")
    @Operation(summary = "查询详细信息")
    ResultVo<QueryResponse> getDetail(@Valid @RequestBody IdRequest<PrimaryKey> request);


    /**
     * 新增
     *
     * @param request 请求
     * @return 响应
     */
    @PostMapping(value = "/save")
    @Operation(summary = "新增")
    ResultVo<SaveResponse> save(@Valid @RequestBody SaveRequest request);


    /**
     * 修改
     *
     * @param request 请求
     * @return 响应
     */
    @PostMapping(value = "/update")
    @Operation(summary = "修改")
    ResultVo<UpdateResponse> update(@Valid @RequestBody UpdateRequest request);


    /**
     * 删除
     *
     * @param request 请求
     * @return 响应
     */
    @PostMapping(value = "/delete")
    @Operation(summary = "删除")
    ResultVo<DeleteResponse> delete(@Valid @RequestBody BatchIdRequest<PrimaryKey> request);
}
